

\documentclass{article}

%\usepackage[top=25mm,bottom=25mm,left=25mm,right=25mm]{geometry}
\usepackage{graphicx}
%\usepackage{amsmath}
%\usepackage{subfig}
%\usepackage{epstopdf}

\begin{document}

\title{ESP - Digital lab 2}
\author{Floris van Nee \& Simon Dirlik}

\maketitle

\section{} %1
The simulink workspace figure can be found in figure \ref{fig:211} (with constant instead of sine input). With a sine input, the output amplitudes were collected for several frequencies and there were plotted to obtain figure \ref{fig:212}.

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/211.png}
	\caption{Answer to problem 2.1. Filter design.}
	\label{fig:211}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/amps21.eps}
	\caption{Answer to problem 2.1. Output amplitude as function of frequency.}
	\label{fig:212}
\end{figure}

\section{} %2
The original impuls response can be found in figure \ref{fig:221} and the original transfer function in figure \ref{fig:222}.

To obtain the coefficients for an improved filter a third restraint need to be added on top of the 1 at DC and 0 at 50Hz (see lecture sheets K1 page 8). We obtain the following equations:

\begin{verbatim}
a=0.1*pi;
b=[1 cos(a) cos(2*a) cos(3*a); 0 sin(a) sin(2*a) sin(3*a);
   1 1 1 1; 0 1 1 1];
c=[0;0;1;0];
b\c;
\end{verbatim}

This leads us to the values:

\begin{verbatim}
ans =

    1.0000
    7.3138
  -16.5296
    9.2159
\end{verbatim}

Filling this in and calculating the impuls response and transfer function leads to figure \ref{fig:223} and \ref{fig:224}. The characteristic is improved.

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/impuls22.eps}
	\caption{Answer to problem 2.2. Original impuls response}
	\label{fig:221}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/pf22.eps}
	\caption{Answer to problem 2.2. Original transfer function.}
	\label{fig:222}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/impuls_improved22.eps}
	\caption{Answer to problem 2.2. Improved impuls response.}
	\label{fig:223}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/pf_improved22.eps}
	\caption{Answer to problem 2.2. Improved transfer function.}
	\label{fig:224}
\end{figure}

\section{} %3
To solve it analytically, the equation $\lambda ^2 + 0.9 = 0$ needs to be solved (because the initial conditions are zero). This has the roots $0 + 0.9487i$ and $0 - 0.9487i$. Using this to calculate C1 and C2, gives us the following equation for the impuls response: $(0.15 - 0.3162i)\cdot 0.9487i^x + (0.15 + 0.3162i)\cdot (-0.9487i)^x$. The plot can be found in figure \ref{fig:231}.

For question b), the impuls response is plotted in figure \ref{fig:232}. This is calculated as follows:

\begin{verbatim}
unit = zeros(1,64);
unit(1) = 1;
direct = filter([0.3 0.6 0.3],[1 0 0.9],unit);
\end{verbatim}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/de23.eps}
	\caption{Answer to problem 2.3.a. Impuls response for differential calculation.}
	\label{fig:231}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/direct23.eps}
	\caption{Answer to problem 2.3.b. Impulse response for direct solving}
	\label{fig:232}
\end{figure}

\section{} %4
\[
H(z) = \frac{B(z)}{A(z)} = \frac{0.3 + 0.6z^{-1} + 0.3z^{-2}}{1 + 0.9z^{-2}}
\]

Transforming this to $H(\omega)$ allows us to determine the gain at different frequencies.

\[
H(\omega) = \frac{0.3e^{-2j\omega} + 0.6e^{-j\omega} + 0.3}{e^{-2j\omega} + 0.9}
\]

For DC this is $H(0) = 0.63$ and for $0.5 f_s$ it is $H(\pi) = 0$. These results match approximately with the results of the previous exercises. If a larger vector length for 2.3.b is chosen, the approximation is better.

\section{} %5
The filter design can be found in figure \ref{fig:251}. Simulatin this and plotting the result gives the following plot, specified in figure \ref{fig:252}.

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/filter25.png}
	\caption{Answer to problem 2.5. Filter design in Simulink}
	\label{fig:251}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/de_impuls_response25.eps}
	\caption{Answer to problem 2.5. Impulse response for Simulink model}
	\label{fig:252}
\end{figure}

\section{} %6
The following code does this. The plots are shown in figure \ref{fig:261}. It can be seen that both systems are stable. However, because the second system has starting values, the beginning is the same. However, after some time, both plots look the same and both go to zero again.

\begin{verbatim}
b=[1 (-9/20)*sqrt(2) 0]
a = [1 -1.8*cos(pi/4) 0.81]
x = zeros(1,111);
x(11)=1;
filter(b,a,x)
filter(b,a,x,filtic(b,a,[1 1]))
\end{verbatim}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/26.eps}
	\caption{Answer to problem 2.6. Result of the filter command without starting values (left) and filter with starting values (right)}
	\label{fig:261}
\end{figure}

\section{} %7
The figures are generated with the following code:

\begin{verbatim}
aa=roots([1 -1.8*cos(pi/4) 0.8])
x=-10:10;
bb=mystepfun(x).*aa(1).^x
bb2=mystepfun(x).*aa(2).^x
\end{verbatim}

The real and imaginary parts of bb and bb2 can be plotted. These are found in figure \ref{fig:271}, \ref{fig:272}, \ref{fig:273} and \ref{fig:274}.

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/firstroot_real.eps}
	\caption{Answer to problem 2.7. First root, real response.}
	\label{fig:271}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/firstroot_imag.eps}
	\caption{Answer to problem 2.7. First root, complex response.}
	\label{fig:272}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/secondroot_real.eps}
	\caption{Answer to problem 2.7. Second root, real response.}
	\label{fig:273}
\end{figure}

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{img/secondroot_imag.eps}
	\caption{Answer to problem 2.7. Second root, complex response.}
	\label{fig:274}
\end{figure}

\end{document}
